package com.example.mytips.assets;

import com.example.mytips.utils.DialogUtils;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

///查看assets/images/的图片
///左边目录：右边图片，选择图片在光标位置插入路径
public class SeeImageAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        // 获取当前项目
        Project project = e.getProject();

        ///上下文
        DataContext context = e.getDataContext();

        ///当前文件
        PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(context);


        // 获取 assets/images/ 目录下的所有子目录
        VirtualFile assetsDir = project.getBaseDir().findFileByRelativePath("assets/images");
        VirtualFile[] subDirs = assetsDir.getChildren();

        // 创建界面窗口
        FlutterAssetsDialog dialog = new FlutterAssetsDialog(e, subDirs, assetsDir, project.getBasePath() + "/");
        DialogUtils.screenCenterShow(dialog);
        dialog.show();
    }
}